package com.rongke.web;

import com.rongke.commons.JsonResp;
import com.rongke.model.IncomeFlow;
import com.rongke.service.IncomeFlowService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @IncomeFlowController
 * @收益流水记录Controller
 * @version : Ver 1.0
 */
@RestController
@RequestMapping(value="/api/incomeFlow")
@Transactional
@CrossOrigin
public class IncomeFlowController {
    private Logger log = Logger.getLogger(this.getClass());
    @Autowired
    private IncomeFlowService incomeFlowService;

    /**
     * @添加收益流水记录
     * @param incomeFlow
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/add", method = RequestMethod.POST)
    public JsonResp addIncomeFlow(@RequestBody IncomeFlow incomeFlow){
        log.debug("添加收益流水记录");
        incomeFlow.setGmtDatetime(new Date());
        incomeFlowService.insert(incomeFlow);
        return JsonResp.ok(incomeFlow);
    }

    /**
     * @修改收益流水记录
     * @param incomeFlow
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/update", method = RequestMethod.POST)
    public JsonResp updateIncomeFlow(@RequestBody IncomeFlow incomeFlow){
        log.debug("修改收益流水记录");
        incomeFlowService.updateById(incomeFlow);
        return JsonResp.ok(incomeFlow);
    }
    /**
     * @根据id查找收益流水记录
     * @param id
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/selectOne", method = RequestMethod.GET)
    public JsonResp selectIncomeFlow(Long id){
        log.debug("查找收益流水记录");
        IncomeFlow incomeFlow = incomeFlowService.selectById(id);
        return JsonResp.ok(incomeFlow);
    }

    /**
     * @根据id查找收益流水记录
     * @param incomeFlow
     * @return 返回值JsonResp
     */
    @RequestMapping(value="/selectIncomeFlowList", method = RequestMethod.GET)
    public JsonResp selectIncomeFlowList(IncomeFlow incomeFlow){
        log.debug("查找收益流水记录");
        List<IncomeFlow> incomeFlows = incomeFlowService.selectIncomeFlowList(incomeFlow);
        return JsonResp.ok(incomeFlows);
    }


    /**
     * @根据条件查找收益流水记录
     * @param incomeFlow
     * @return 返回值JsonResp
     */
    @RequestMapping(value = "/selectByCondition", method = RequestMethod.POST)
    public JsonResp selectIncomeFlowByCondition(@RequestBody IncomeFlow incomeFlow){
        log.debug("根据条件查找收益流水记录");
        if(incomeFlow==null)
            return JsonResp.toFail("参数不能为空");
        List<IncomeFlow> incomeFlowList=incomeFlowService.selectByCondition(incomeFlow);
        return JsonResp.ok(incomeFlowList);
    }

}
